home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / gsdbloo.exe / DEMOR001.PAS < prev    next >
Pascal/Delphi Source File  |  1992-02-29  |  4KB  |  133 lines

  1. program DemoR001;
  2. {------------------------------------------------------------------------------
  3.                          DBase Relational File Maker
  4.                                Useless Examples
  5.                                  Demo Program
  6.  
  7.        Copyright (c)  Richard F. Griffin
  8.  
  9.        10 February 1992
  10.  
  11.        102 Molded Stone Pl
  12.        Warner Robins, GA  31088
  13.  
  14.        -------------------------------------------------------------
  15.  
  16.        This unit creates the files that will be used to demonstrate
  17.        how to link the relationships between dBase files for data
  18.        retrieval based on common fields in two files.
  19.  
  20.        This will first build a master file and then create a transaction
  21.        file using the UNIQUEID field in the master file as the key.  The
  22.        transactions will insert the UNIQUEID field in each record as the
  23.        MASTERID field.  This field will be used to link back to the master
  24.        record.
  25.  
  26.        A Master file index on the UNIQUEID field will be created.
  27.        A Transaction file index on the MASTERID field will be created.
  28.  
  29.        The Master file will have the structure defined in GS_GENF.PAS.
  30.        The Transaction file structure is:
  31.  
  32.              MASTERID     C    8   0      Uses UNIQUEID from Master Record
  33.              FULLNAME     C   40   0      In Lastname~FirstName format
  34.              TRANDATE     D    8   0
  35.              AMOUNT       N    8   2
  36.              PAYTYPE      C    1   0
  37.  
  38. -------------------------------------------------------------------------------}
  39.  
  40. uses
  41.    CRT,
  42.    GS_Strng,
  43.    GS_Date,
  44.    GS_dBase,
  45.    GS_dBFld,
  46.    GS_GenF,
  47.    GS_dB3Wk;
  48.  
  49. type
  50.    FldRecPtr   = ^FldRecTyp;
  51.    FldRecTyp   = array[1..GS_dBase_MaxRecField] of GS_dBase_Field;
  52.  
  53. var
  54.    MstrFile : GS_dBFld_Objt;
  55.    TranFile : GS_dBFld_Objt;
  56.    f : FldRecPtr;
  57.    t : string;
  58.    ix : integer;
  59.    rn : integer;
  60.    FLoc : integer;
  61.  
  62.    tfRanNum   : word;
  63.    tfFullName : string[40];
  64.    tfTranDate : longint;
  65.    tfAmount   : real;
  66.    tfPayType  : real;
  67.    tfPayTypeS : string[1];
  68.  
  69. procedure InsertField(s : string; t : char; l,d : integer);
  70. begin
  71.    if FLoc >= GS_dBase_MaxRecField then exit;
  72.    inc(FLoc);
  73.    s := AllCaps(s);
  74.    CnvStrToAsc(s,f^[FLoc].FieldName,11);
  75.    f^[FLoc].FieldType := t;
  76.    f^[FLoc].FieldLen := l;
  77.    f^[FLoc].FieldDec := d;
  78.    f^[FLoc].FieldAddress := 0;
  79.    FillChar(f^[FLoc].Reserved,20,#0);
  80. end;
  81.  
  82. Procedure MakeTranFile;
  83. begin
  84.    New(f);
  85.    FLoc := 0;
  86.    InsertField('MASTERID','C',8,0);
  87.    InsertField('FULLNAME','C',40,0);
  88.    InsertField('TRANDATE','D',8,0);
  89.    InsertField('AMOUNT','N',8,2);
  90.    InsertField('PAYTYPE','C',1,0);
  91.    GS_dB3_Build('DEMOR1TF',f,FLoc);
  92. end;
  93.  
  94. begin
  95.    ClrScr;
  96.    Writeln('Making DEMOR1MF.DBF Master File');
  97.    MakeTestData('DemoR1MF', 20, false);
  98.    WriteLn('DEMOR1MF Complete');
  99.    Writeln('Making DEMOR1TF.DBF Transaction File');
  100.    MakeTranFile;
  101.    WriteLn('DEMOR1TF Complete');
  102.    WriteLn('Creating Transactions');
  103.    MstrFile.Init('DEMOR1MF');
  104.    MstrFile.Open;
  105.    MstrFile.IndexTo('DEMOR1ID','UNIQUEID');
  106.    MstrFile.Index('DEMOR1ID');
  107.    TranFile.Init('DEMOR1TF');
  108.    TranFile.Open;
  109.    TranFile.IndexTo('DEMOR1TN','MASTERID');
  110.    TranFile.Index('DEMOR1TN');
  111.    Randomize;
  112.    for rn := 1 to 50 do
  113.    begin
  114.       ix := Random(20) + 1;
  115.       MstrFile.GetRec(ix);
  116.       tfFullName := MstrFile.StringGet('LASTNAME') + '~' +
  117.                     MstrFile.StringGet('FIRSTNAME');
  118.       tfTranDate := GS_Date_Curr - Random(31);
  119.       tfAmount := (Random(30000) + 100);
  120.       tfAmount := tfAmount/100;
  121.       tfPayType := Random(4);
  122.       str(tfPayType:1:0,tfPayTypeS);
  123.       TranFile.Blank;
  124.       TranFile.FieldPut('MASTERID',MstrFile.FieldGet('UNIQUEID'));
  125.       TranFile.StringPut('FULLNAME',tfFullName);
  126.       TranFile.DatePut('TRANDATE',tfTranDate);
  127.       TranFile.NumberPut('AMOUNT',tfAmount);
  128.       TranFile.FieldPut('PAYTYPE',tfPayTypeS);
  129.       TranFile.Append;
  130.    end;
  131.    MstrFile.Close;
  132.    TranFile.Close;
  133. end.